<?php
	include("../include/init.php");//将配置文件全部加载进来
	include("../include/check_login.php");//登录

	$admin = new sql_class("admin");



	
	//连表查询
	/*$select = "AS article LEFT JOIN pre_article_cate AS cate ON article.artcate_id = cate.artcate_id";
	$artcate_list = $insert->select("1","",$select)->getAll();
	var_dump($artcate_list);exit;*/



	//单条删除
	$admin_id = isset($_GET['admin_id']) ? $_GET['admin_id'] : 0;
	if($admin_id){
		$admin_del = $admin->delete("admin_id = $admin_id");
		if($admin_del){
			show_msg("删除管理员成功","admin_list.php");
			exit;	
		}else{
			show_msg("删除管理员成失败","admin_list.php");
			exit;
		}
	}

	//多条删除
	$admin_id = isset($_GET['id']) ? implode(",",$_GET['id']) : 0;
	if($admin_id){
		$where = "admin_id IN($admin_id)";
		$affect_id =$admin->delete($where);
		if($affect_id){
			show_msg("批量删除管理员成功","admin_list.php");
			exit;
		}else{
			show_msg("批量删除管理员失败","admin_list.php");
			exit;
		}

	}

	$keywords = isset($_GET['keywords']) ? $_GET['keywords'] : 0;
	
	$where = "";
	if(!empty($keywords)){
		$where = "admin_name = '$keywords'";
	}else{
		$where = 1;
	}
	
	$current = isset($_GET['page']) ? $_GET['page'] : 1;//获取页数
	$limit = 6;
	$size = 4;
	$count = $admin->select($where,"COUNT(*) AS c")->getOne();
	
	$page_str = page($current,$count['c'],$limit,$size);
	$start = ($current - 1)*$limit;
	$admin_list = $admin->select($where)->orderBy(["admin_id","DESC"])->limit([$start,$limit])->getAll();
	


	$smarty->assign("admin_list",$admin_list);
	$smarty->assign("page_str",$page_str);
	$smarty->display("admin/admin_list.html");



?>